package ashok.corejava.threads;

public class ThreadSynchronizationOne {

	private int count = 0;
		public static void main(String []args){
			ThreadSynchronizationOne one = new ThreadSynchronizationOne();
			
			one.dowork();
	}
		public synchronized void increment(){
			count++;
		}
		
		public void dowork(){
			Thread t1= new Thread(new Runnable(){
				public void run(){
					for(int i=0;i<10000;i++){
						increment();
					}
				}
			});
			

			Thread t2= new Thread(new Runnable(){
				public void run(){
					for(int i=0;i<10000;i++){
						increment();
					}
				}
			});
		
			t1.start();
			t2.start();
			
			try {
				t1.join();
				t2.join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
			//Immediate count will be 0
			System.out.println("Count is :"+count);
		}
}
